package com.iseastar.guojiang.team;

import android.os.Bundle;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ListView;

import com.iseastar.BaseActivity2;
import com.iseastar.guojiang.consts.MsgID;
import com.iseastar.guojiang.logic.AppHttp;
import com.iseastar.guojiang.logic.JSON;
import com.iseastar.guojiang.model.CourierTeamMonthBean;
import com.iseastar.guojiang.model.CourierTeamPastAchievementsBean;
import com.iseastar.guojiang.model.ReqResult;
import com.iseastar.guojiang.team.adapter.CourierTeamPastAchievementsAdapter;
import com.shouhuobao.station.R;

import java.util.ArrayList;

import droid.frame.view.xlist.SListView;

/**
 * 战队过往成就
 * Created by lidandan on 2018/6/13.
 */
public class CourierTeamPastAchievementsActivity extends BaseActivity2 {

    private CourierTeamPastAchievementsAdapter mAdapter = null;
    private SListView listview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        int teamId = getIntent().getIntExtra("teamId", 0);
        super.onCreate(savedInstanceState);
        showLoadingDialog(null);
        AppHttp.getInstance().courierTeamAchievement(teamId);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.courier_team_past_achievements_activity);
        super.findViewById();
        getAppTitle().setCommonTitle("战队过往成就");
        listview = findViewById(R.id.achievements_listview);
        mAdapter = new CourierTeamPastAchievementsAdapter(null, getContext());
        listview.setAdapter(mAdapter);

    }

    @Override
    public boolean handleMessage(Message msg) {
        switch (msg.what) {
            case MsgID.courier_team_pass_achievement_list:
                cancelLoadingDialog();
                final ReqResult<CourierTeamPastAchievementsBean> result = JSON.parseList(msg.obj, CourierTeamPastAchievementsBean.class);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (checkLoginStatus(result)) {
                            if (mAdapter == null) {
                                mAdapter = new CourierTeamPastAchievementsAdapter(result.getResultList(), getContext());
                                listview.setAdapter(mAdapter);
                            } else {
                                mAdapter.setItems(result.getResultList(), true);
                            }
                        } else {
                            showToast(result.getMessage());
                        }
                    }
                });
                return true;
            default:
                return super.handleMessage(msg);
        }

    }
}
